<template>
  <div class="goods">
    <!-- 搜索 -->
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item>
        <el-button type="primary" @click="onSearchFn">添加</el-button>
      </el-form-item>
    </el-form>
    <!-- 内容 -->
    <el-table :data="categoryLists" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="180"> </el-table-column>
      <el-table-column prop="name" label="分类名称" width="180">
      </el-table-column>
      <el-table-column prop="parent_id" label="分类级别">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{
            scope.row.parent_id == 0 ? "顶级分类" : "子分类"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="wap_banner_url" label="图片">
        <template slot-scope="scope">
          <img
            :src="scope.row.wap_banner_url"
            style="width: 50px; height: 50px"
          />
        </template>
      </el-table-column>
      <el-table-column prop="is_show" label="是否显示">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{
            scope.row.is_show == 1 ? "是" : "否"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="sort_order" label="排序"> </el-table-column>
      <el-table-column label="操作" prop="id">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="handleEdit(`${scope.row.id}`)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {
  getUserByToken,
  getGoodLists,
  getGoodInfo,
  getCategoryLists,
} from "../../request/httpApi";

export default {
  data() {
    return {
      formInline: {
        user: "",
        region: "",
      },

      //分类请求接口数据
      categoryLists: [],
    };
  },

  created() {
  
    //发送分类请求
    getCategoryLists().then((res) => {
      console.log(res);
      if (res.errno == 0) {
        this.categoryLists = res.data;
      }
    });
  },
  methods: {
    //点击编辑, 跳转到编辑页面
    handleEdit(val) {
      //拿到id
      // console.log(val);
      this.$router.push("/editcategory/" + val);
    },
    //添加
    onSearchFn() {},
  },
};
</script>

<style lang="less">
.goods {
  padding-top: 10px;
  padding-left: 10px;
  padding-right: 10px;
  background-color: #fff;
}
</style>